package com.ncdnapp.core.thread;

import org.noear.solon.Utils;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class ThreadFactory {
    public static ExecutorService getVirtualThreadPool() {
        return getVirtualThreadPool(null);
    }

    public static ExecutorService getVirtualThreadPool(String name) {
        if (Utils.isBlank(name)) {
            name = "virtual-thread";
        }
        name += "-";
        ExecutorService executorService = Executors.newThreadPerTaskExecutor(
                Thread.ofVirtual().name(name, 0).factory()
        );
        return executorService;
    }
}
